package com.zjxf.base.bean.annotation;

import com.zjxf.base.common.SysConst;

import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.Payload;
import java.lang.annotation.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @author zhang tong
 * date: 2019/2/18 16:02
 * description:
 */
@Documented
@Constraint(validatedBy = CompressedPackageSuffix.Validator.class)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface CompressedPackageSuffix {

    String message() default "压缩包类型错误";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    class Validator implements ConstraintValidator<CompressedPackageSuffix, Integer> {
        @Override
        public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
            return SysConst.getFolderTypeByCode(integer).isPresent();
        }
    }
}
